package com.s.core.root.strategy.factor.pic;

import com.s.core.root.data._AllData;
import com.s.core.root.data._PicN;
import com.s.core.root.data._PointN;
import com.s.core.root.strategy.base.Factor;
import com.s.core.root.strategy.base.Feature;
import com.s.core.root.strategy.factor.pic.combination.F_Pic_LastStrong;
import com.s.core.root.strategy.factor.point.F_Point_Strong;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.function.Function;

/**
 * Pic特征：描述两个point(其中一个是lastPoint)形成波动
 */
@NoArgsConstructor
@Data
public class F_Pic_ActivityPair implements Factor, Feature {
    //500/5252
    public static final Function<Integer, Integer> TOTAL_POS_N_LIMIT = total ->
            new BigDecimal(total).multiply(new BigDecimal("0.0952")).
                    setScale(0, RoundingMode.UP).intValue();

    public static final int MAX_INTER = 6;

    @Override
    public void process(_AllData allData) {
        for (_PicN picN : allData.picNMap.values()) {
            if (picN.containFeature(F_Pic_LastStrong.class)) {
                process(picN.getPointNList1(), picN);
            }
        }
    }

    private void process(List<_PointN> pointNList, _PicN picN) {
        if (pointNList.size() < 3) {
            return;
        }
        _PointN lastPoint = pointNList.get(pointNList.size() - 1);
        _PointN lastPoint2 = pointNList.get(pointNList.size() - 2);
        if (lastPoint2.isTp()) {
            return;
        }
        for (int i = pointNList.size() - 3;
             i >= 0 && i >= pointNList.size() - 2 - MAX_INTER; i--) {
            _PointN lastPointI = pointNList.get(i);
            if (lastPointI.containFeature(F_Point_Strong.class)
                    && lastPointI.pos() < lastPoint2.pos() && lastPoint.pos() < lastPoint2.pos()
                    && lastPointI.pos() + lastPoint.pos() <= TOTAL_POS_N_LIMIT.apply(lastPoint.total)) {
                picN.addFeature(new F_Pic_ActivityPair());
                break;
            }
        }
    }
}